home *** CD-ROM | disk | FTP | other *** search
/ El Mac 1 / Magazine.iso / EL MAC 1 / Shareware / HyperCard / XCMD Docs / CompileIt! Source Code / IconListDispatch(selector,listH < prev    next >
Encoding:
Text File  |  1995-08-19  |  4.3 KB  |  102 lines  |  [TEXT/ttxt]

  1. function IconListDispatch selector,listHandle,param2,param3
  2.   if listhandle="0" then return "Error"
  3.   if listhandle= "I can't use that rectangle! It's too small for even 1 icon!" then return "Error"
  4.   if selector = "1" or selector = "new" then return newList(param2,param3)
  5.   else if listhandle = "" then return "Error"
  6.   else if selector="2" or selector = "draw" then return drawList(listHandle)
  7.   else if selector = "3" or selector = "setScroll" then return ss(listHandle,param2)
  8.   else if selector = "4" or selector = "kill" then return kill(listHandle)
  9.   else if selector = "5" or slector = "getScroll" then return listHandle@@.longIntType[3]
  10.   else if selector = "6" or selector = "getnumonline" then return listHandle@@.longIntType[4]
  11.   else if selector = "7" or selector = "getnumlineonscreen" then return listHandle@@.longIntType[5]
  12.   else if selector = "8" or selector = "getlinecount" then return listHandle@@.longIntType[6]
  13.   else if selector = "9" or selector = "getnumicons" then return listHandle@@.longIntType[7]
  14.   else if selector = "10" or selector = "getrect" then return listHandle@@.integertype[2] & "," & listHandle@@.integertype[1] & "," & listHandle@@.integertype[4] & "," & listHandle@@.integertype[3]
  15. end IconListDispatch
  16.  
  17. --type myHandle
  18. --listRect        rectangle    8         myHandle@@.longIntType[1]..myHandle@@.longIntType[2]
  19. --scroll           LongInt       4         myHandle@@.longIntType[3]
  20. --NumOnLine    LongInt       4         myHandle@@.longIntType[4]
  21. --NumLinesVis LongInt       4         myHandle@@.longIntType[5]
  22. --NumLines      LongInt       4         myHandle@@.longIntType[6]
  23. --iconCount      LongInt       4        myHandle@@.longIntType[7]
  24. --iconHandles   array of LongInt[1..iconCount]    iconCount*4
  25.  
  26. function kill myHandle
  27.   put myHandle@@.longIntType[7] into j
  28.   repeat with g = 1 to j
  29.     disposhandle myHandle@@.longIntType[j+7]
  30.   end repeat
  31.   disposhandle myhandle
  32. end kill
  33.  
  34. function ss myHandle,news
  35.   put news into myHandle@@.longIntType[3]
  36. end ss
  37.  
  38. global l1:L,l2:L,temp:R
  39. function drawlist myHandle
  40.   put myHandle@@.longIntType[1] into l1
  41.   put myHandle@@.longIntType[2] into l2
  42.   put l1.integertype[2] into r1
  43.   put l1.integertype[1] into r2
  44.   put l2.integertype[2] into r3
  45.   put l2.integertype[1] into r4
  46.   put myHandle@@.longIntType[3] into scroll
  47.   put myHandle@@.longIntType[4] into numonline
  48.   put myHandle@@.longIntType[5] into numlinevis
  49.   put myHandle@@.longIntType[6] into numlines
  50.   put myHandle@@.longIntType[7] into iconcount
  51.   put (scroll*numonline)+1 into startat
  52.   put 34 into size1
  53.   repeat min(numlinevis,numlines)
  54.     repeat min(numonline,iconcount)
  55.       if startat>Iconcount then exit repeat -- ΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔVERY VERY IMPORTANT.
  56.       setrect temp r1,r2,r1+32,r2+32
  57.       plotIcon temp,myHandle@@.longIntType[startat+7]
  58.       add size1 to r1
  59.       add 1 to startat
  60.     end repeat
  61.     put l1.integertype[2] into r1
  62.     add size1 to r2
  63.   end repeat
  64. end drawlist
  65.  
  66. function newList icons,ListRect
  67.   put the number of items in icons*4 into j -- space for icons' handles
  68.   add 4 to j -- space for icon count
  69.   add 8 to j -- space for rectangle
  70.   add 4 to j -- space for scroll
  71.   add 4 to j -- space for number of lines
  72.   add 4 to j -- number on 1 line
  73.   add 4 to j -- number of lines visible
  74.   put newHandleClear(j) into myHandle
  75.   hlock myhandle
  76.   setRect myHandle@@,item 1 of listrect,item 2 of listrect,item 3 of listrect,item 4 of listrect
  77.   hunlock myHandle
  78.   put 34 into size1
  79.   get (item 3 of listrect-item 1 of listrect) div size1
  80.   if it = 0 then
  81.     disposHandle myHandle
  82.     return "I can't use that rectangle! It's too small for even 1 icon!"
  83.   end if
  84.   put it into myHandle@@.longIntType[4] -- num on line
  85.   if ((item 4 of listrect-item 2 of listrect) div size1) = 0 then
  86.     disposHandle myHandle
  87.     return "I can't use that rectangle! It's too small for even 1 icon!"
  88.   end if
  89.   put ((item 4 of listrect-item 2 of listrect) div size1) into myHandle@@.longIntType[5]
  90.   put the number of items in icons*1 into ni
  91.   if ni mod it ≠0 then
  92.     put (ni div it)+1 into myHandle@@.longIntType[6]
  93.   else put ni div it into myHandle@@.longIntType[6]
  94.   put ni into myHandle@@.longIntType[7]
  95.   -- now to load the icons
  96.   repeat with nowOn = 1 to ni
  97.     get GetIcon(item nowOn of icons)
  98.     detachresource it -- if hypercard loads the icon, it won't touch my copy
  99.     put it into myHandle@@.longIntType[7+nowOn]
  100.   end repeat
  101.   return myHandle
  102. end newList